<?php
/* MyMeeting is an online meeting management software.
 * Copyright (C) 2009 Government Of Malaysia
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * @author: Abdullah Zainul Abidin, Nuhaa All Bakry
 *          Eavay Javay Barnad, Sarogini Muniyandi, Teow Jit Huan
 *
 */
//New controller for 2.3 - Protocol
class ProtocolsController extends AppController {

    var $name = 'Protocols';
    var $helpers = array('Html', 'Form');

    function index() {
        $this->Protocol->recursive = 0;
        $this->paginate=array('order'=>'Protocol.rank Asc');
        $this->set('protocols', $this->paginate());
    }
    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid Protocol.', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->set('protocol', $this->Protocol->read(null, $id));
    }

    function add() {
        if (!empty($this->data)) {
            $this->Protocol->create();
            if ($this->Protocol->save($this->data)) {
                $this->Session->setFlash(__('The Protocol has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Protocol could not be saved. Please, try again.', true));
            }
        }
    }

    function edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid Protocol', true));
            $this->redirect(array('action'=>'index'));
        }
        if (!empty($this->data)) {
            if ($this->Protocol->save($this->data)) {
                $this->Session->setFlash(__('The Protocol has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Protocol could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Protocol->read(null, $id);
        }
    }

    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for Protocol', true));
            $this->redirect(array('action'=>'index'));
        }
        if ($this->Protocol->delete($id)) {
            $this->Session->setFlash(__('Protocol deleted', true));
            $this->redirect(array('action'=>'index'));
        }
    }

}
?>
